package course.service.impl;

import course.dao.ZhuanyeDao;
import course.dao.impl.ZhuanyeDaoImpl;
import course.pojo.entity.Zhuanye;
import course.pojo.vo.Page;
import course.service.ZhuanyeService;
import course.utils.JDBCUtil;

import java.sql.Connection;
import java.util.List;

/**
 * @author HLF
 * @date 2022/6/30 21:26
 */
public class ZhuanyeServiceImpl implements ZhuanyeService {
    private ZhuanyeDao zhuanyeDao = new ZhuanyeDaoImpl();

    @Override
    public Zhuanye getById(Integer zid) {
        Connection connection = JDBCUtil.getConnection();
        Zhuanye byId = zhuanyeDao.getById(zid, connection);
        JDBCUtil.closeConnection(connection);
        return byId;
    }

    @Override
    public int addZhuanye(Zhuanye zhuanye) {
        Connection connection = JDBCUtil.getConnection();
        int i = zhuanyeDao.addZhuanye(zhuanye, connection);
        JDBCUtil.closeConnection(connection);
        return i;
    }

    @Override
    public int updateById(Zhuanye zhuanye) {
        Connection connection = JDBCUtil.getConnection();
        int i = zhuanyeDao.updateById(zhuanye, connection);
        JDBCUtil.closeConnection(connection);
        return i;
    }

    @Override
    public int deleteById(Integer zid) {
        Connection connection = JDBCUtil.getConnection();
        int i = zhuanyeDao.deleteById(zid, connection);
        JDBCUtil.closeConnection(connection);
        return i;
    }

    @Override
    public List<Zhuanye> getList() {
        Connection connection = JDBCUtil.getConnection();
        List<Zhuanye> list = zhuanyeDao.getList(connection);
        JDBCUtil.closeConnection(connection);
        return list;
    }

    /**/

    @Override
    public int deleteSelect(List<Integer> ids) {
        Connection connection = JDBCUtil.getConnection();
        int i = zhuanyeDao.deleteSelect(ids, connection);
        JDBCUtil.closeConnection(connection);
        return i;
    }

    @Override
    public long count() {
        Connection connection = JDBCUtil.getConnection();
        long count = zhuanyeDao.count(connection);
        JDBCUtil.closeConnection(connection);
        return count;
    }

    @Override
    public Page<Zhuanye> page(Integer pageNo) {
        Connection connection = JDBCUtil.getConnection();
        Page<Zhuanye> page = zhuanyeDao.page(pageNo, connection);
        JDBCUtil.closeConnection(connection);
        return page;
    }

    @Override
    public Page<Zhuanye> query(String cname, Integer pageNo) {
        Connection connection = JDBCUtil.getConnection();
        Page<Zhuanye> page = zhuanyeDao.query(cname, pageNo, connection);
        JDBCUtil.closeConnection(connection);
        return page;
    }

    @Override
    public List<Zhuanye> getListByCid(Integer cid) {
        Connection connection = JDBCUtil.getConnection();
        List<Zhuanye> list = zhuanyeDao.getListByCid(cid, connection);
        JDBCUtil.closeConnection(connection);
        return list;
    }

    @Override
    public Zhuanye getByZname(String zname) {
        Connection connection = JDBCUtil.getConnection();
        Zhuanye byZname = zhuanyeDao.getByZname(zname, connection);
        JDBCUtil.closeConnection(connection);
        return byZname;
    }

    @Override
    public List<Zhuanye> selectBathByIds(List<Integer> ids) {
        Connection connection = JDBCUtil.getConnection();
        List<Zhuanye> zhuanyes = zhuanyeDao.selectBathByIds(ids, connection);
        JDBCUtil.closeConnection(connection);
        return zhuanyes;
    }
}
